Skip to content

feat(api): workflow trigger health and enablement through the v2 API - #9853

Merged
waleedlatif1 merged 9 commits into
stagingfrom
feat/v2-workflow-trigger-health
Nov 10, 2026
Merged

waleedlatif1 merged 9 commits into
stagingfrom
feat/v2-workflow-trigger-health

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Adds GET /api/v2/workflows/{workflowId}/triggers: every trigger the live deployment serves (schedules, polling, internal event, and push webhook triggers) with kind, enabled, status, failure count, last failure, and next/last run plus cron for schedules
  • Adds PATCH /api/v2/workflows/{workflowId}/triggers/{blockId} with { enabled }: enabling resets failure counters, re-arms nextRunAt, and clears polling backoff; disabling stops Sim accepting the trigger without tearing down the provider registration. A disable lasts until the next deploy, the same way a redeploy already clears an auto-disabled trigger
  • Liveness matches delivery exactly: v2 schedules use the dispatcher's active-version test, webhooks the routing/poller predicate. Writes are conditional updates that can never revive a retired, archived, or older-version row, and a block with several live webhook rows switches them together
  • Moves the internal schedule reactivate/disable and webhook enable routes onto the same use case. Statuses, messages, and response bodies are unchanged, except cross-tenant callers now get a concealed 404, a non-live row is a 404 instead of being toggled, and webhook toggles now write a webhook.updated audit entry
  • Fixes an auto-disabled webhook silently disappearing from /deployment's view of the world (it now shows up in /triggers as disabled), and makes polling auto-disable a single conditional update so an enable can't be switched straight back off
  • triggers.webhook permission-group gating on enable is preserved; CLI workflows triggers list|update; regenerated OpenAPI, CLI, MCP operations, and route table

Type of Change

  • New feature

Testing

  • apps/sim/lib/workflows/application/triggers.integration.ts (14 passing) against PostgreSQL: live-row listing, write-time liveness refusal, counter/backoff reset, scalar provider configs, versionless schedules, multi-row blocks, cron validation, lock, role and tenant boundaries, capability gate, no-op audit, poll auto-disable threshold; reverting the liveness predicate, capability gate, no-op detection, counter reset, dispatcher predicate, and config guard each turns its test red
  • operations.test.ts, list-pagination.test.ts, copilot-route-inventory.test.ts
  • tsc on apps/sim; check:openapi, cli-api, cli-docs, mcp-operations, v2-route-table, route-verbs, permission-group-enforcement, capability-subject, principal-kind-parity, api-validation:strict, source-conventions, test-patterns, boundaries; biome

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

GET /api/v2/workflows/{workflowId}/triggers lists every schedule, polling,
internal-event, and webhook trigger the live deployment serves, disabled
ones included, with failure counts. PATCH .../triggers/{blockId} enables or
disables one without redeploying: enabling resets the failure counters,
re-arms a schedule's next run, and clears polling backoff; a schedule with
no future run is a 409. Liveness is the active deployment version plus an
active or legacy registration, enforced inside one conditional UPDATE, so
a candidate, retired, or older-version row is never revived.

Adds workflows.triggers.read / workflows.triggers.set_enabled, the
WEBHOOK_UPDATED audit action, and the CLI commands
`workflows triggers list|update`.
… the trigger use case

PUT /api/schedules/[id] and PATCH /api/webhooks/[id] now call
setWorkflowTriggerEnabled, which owns authorization, the workflow lock, the
triggers.webhook gate on re-enabling, and audit. Both keep their response
shapes. The id must name the live deployment's row, so these routes can no
longer revive a candidate, retired, or older-version registration, and the
webhook route no longer writes an arbitrary failedCount (failedCount: 0 is
still accepted and ignored). Webhook re-enable and disable are now audited.

Removes the mock-based route tests the integration suite replaces.
…ock, keep legacy route behavior

Live rows now use the delivery and editor deployment test (active version,
or versionless deploy with no version id) and no longer filter on
registration status, so the editor never shows a row the legacy toggle
rejects. A block target switches all of its live rows in one transaction;
a row id switches only that row. Disabling a completed schedule moves it to
disabled again, a cron with no future run is a 400 with the legacy message,
and same-workspace role denials keep their legacy 403 bodies.
… atomic poll auto-disable

The v2 list and block target read schedules with the dispatcher's own
predicate, so a versionless schedule that never fires is not reported; the
legacy row-id route keeps it for the editor. Enabling clears poll backoff
only on polling rows with an object config. An unknown schedule status reads
as active instead of failing the list. markWebhookFailed increments and
auto-disables in one statement, so a concurrent enable is never switched off
by a decision made on the old count. Documents that a disable lasts until the
next deploy or activation, and that workspace keys are not governed by the
webhook capability.
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 10, 2026 9:40pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issues remain.

Summary

Adds v2 endpoints and CLI commands to inspect trigger health and enable or disable triggers without redeploying.

  • The v2 API lists and switches triggers on live workflow deployments.
  • Schedule and webhook editor controls use shared trigger enablement rules.
  • Polling failure counts and auto-disable state change together.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[V2 trigger PATCH] --> C[Shared trigger use case]
  B[Internal schedule or webhook route] --> C
  C --> D[Check workspace access and workflow lock]
  D --> E[Find eligible trigger rows]
  E --> F[Check permission when enabling webhooks]
  F --> G[Update rows in one transaction]
  G --> H{Every targeted row updated?}
  H -->|Yes| I[Return state and record changes]
  H -->|No| J[Roll back and reread]
  J --> K[Return no-op or conflict]
Loading

Reviews (2) · Last reviewed commit: "fix(triggers): v2 reports only triggers ..." · Reviewed by Greptile

Comment thread apps/sim/app/api/webhooks/[id]/route.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/api/webhooks/[id]/route.ts Resolved
…TCH, switch all or nothing

The v2 list and block target require the active version of a deployed
workflow for both tables, since webhook processing refuses a versionless or
undeployed row; the legacy row-id routes keep the editor's view. PATCH
/api/webhooks/[id] admits a workflow run's executor delegation again, and
setTriggerEnabled admits the executor service. A multi-row switch rolls back
entirely when any row was retired or switched concurrently, so a conflict
commits nothing. Adds the two new CLI fences to the docs content baseline.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 34 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

This branch was previously deployed

1 inactive deployment
Preview — ddda582c Deployed Nov 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant